﻿$(document).ready(function () {
    xGmap_ChiTietPT();
    //GetPhongTroSame();
    //
    Click_Popup_VIP_PTCT();
    ClickUP_TU_DONG_PTCT();
});

//// Popup Up tin VIP
function Click_Popup_VIP_PTCT() {
    $("#btnUpVIP_ptct").colorbox({
        iframe: true
    , innerWidth: 665
    , innerHeight: 330
    , opacity: 0.9
    , title: "KÍCH HOẠT TIN VIP CHỈ TRONG 1 PHÚT"
    });
}
// Popup Up tin tu dong
function ClickUP_TU_DONG_PTCT() {
    $("#btnAutoUp_ptct").colorbox({
        iframe: true
    , innerWidth: 762
    , innerHeight: 435
    , opacity: 0.9
    , title: "KÍCH HOẠT UP TIN TỰ ĐỘNG CHỈ TRONG 2 PHÚT"
    });
}

//Lấy danh sách phòng trọ cùng khu vực, kiểu phòng trọ
function GetPhongTroSame() {
    $("#loader").show();
    $.ajax({
        type: "POST",
        url: "/Default.aspx/fncLoadMorePhongTro",
        data: '{iPageIndex: 1'
            + ',iPageSize: 10'
            + ',strKhuVuc: "' + strKhuVuc + '"'
            + ',iGia: 0'
            + ',iDienTich: 0'
            + ',strKieuPT: "' + strKieuPhongTro + '"'
            + ',strUS_ID: ""'
            + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var Data = response.d;
            $(".lstPhongTro").append(Data);
            $("#loader").hide();
        },
        failure: function (response) {
            //alert("failure: " + response.d);
        },
        error: function (response) {
            //alert("error: " + response.d);
        }
    });
}

//**************************Setup Google Map****************************************
var objMap;
function xGmap_ChiTietPT() {
    var KinhDo = $("#hdKinhDo").val();
    var ViDo = $("#hdViDo").val();
    var latlng = new google.maps.LatLng(KinhDo, ViDo);

    //Khởi tạo googleMap - load vị trí mặc định
    var myOptions = {
        zoom: 16,
        center: latlng,
        scrollwheel: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP // can be SATELLITE  , HYBRID, ROADMAP or TERRAIN
    };
    objMap = new google.maps.Map(document.getElementById("Google_Map"), myOptions);

    //Gọi hàm đánh dấu
    var marker = add_marker(KinhDo, ViDo, "Click để xem địa chỉ!", $(".adress").text()); // pass in as Latitude, then Longitude
    marker.setMap(objMap);
}
//Đánh dấu vị trí trên bản đồ
function add_marker(lat, lng, title, box_html) {
    var infowindow = new google.maps.InfoWindow({
        content: box_html
    });
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat, lng),
        map: objMap,
        title: title
    });
    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(objMap, marker);
    });
    return marker;
}
//**********************************************************************************

//************************************SLIDE Ảnh***************************************
var currentImage;
var currentIndex = -1;
var interval;
function showImage(index) {
    if (index < $('#bigPic img').length) {
        var indexImage = $('#bigPic img')[index]
        if (currentImage) {
            if (currentImage != indexImage) {
                $(currentImage).css('z-index', 2);
                clearTimeout(myTimer);
                $(currentImage).fadeOut(250, function () {
                    myTimer = setTimeout("showNext()", 3000);
                    $(this).css({ 'display': 'none', 'z-index': 1 })
                });
            }
        }
        $(indexImage).css({ 'display': 'block', 'opacity': 1 });
        currentImage = indexImage;
        currentIndex = index;
        $('#thumbs li').removeClass('active');
        $($('#thumbs li')[index]).addClass('active');
    }
}

function showNext() {
    var len = $('#bigPic img').length;
    var next = currentIndex < (len - 1) ? currentIndex + 1 : 0;
    showImage(next);
}

var myTimer;

$(document).ready(function () {
    myTimer = setTimeout("showNext()", 3000);
    showNext(); //loads first image
    $('#thumbs li').bind('click', function (e) {
        var count = $(this).attr('rel');
        showImage(parseInt(count) - 1);
    });
});
//************************************************************************************